package com.hns.can.report.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.master.entity.BaseCarInfoEntity;
import com.hns.can.master.entity.BaseDrvInfoEntity;
import com.hns.can.master.entity.BaseLineInfoEntity;
import com.hns.can.report.entity.BiLineIdxInfoEntity;
import com.hns.can.report.vo.LineAnaLineVo;
import com.hns.can.report.vo.LineRelevantCarVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 线路画像
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Service
public class LineAnaService extends CommonService {
    
   /**
    * 填充代码描述
    */
    @Autowired
    private FillCodeDscValue codeDscValue;
    
   /**
    * 获取线路信息
    * @param carId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings({"unchecked"})
    public BaseLineInfoEntity getLineAnaLineInfo(String lineId) throws Exception {
          List<BaseLineInfoEntity> list = PubUtil.convertListMapToObject(
             		this.sqlMapDao.selectList("lineAna.getLineAnaLineInfo", lineId), BaseLineInfoEntity.class);
          Map<String,String> map2 = new HashMap<String,String>();
          map2.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);   
          FillParamsVo vo2 = new FillParamsVo("organId", map2);
          codeDscValue.fillInfoValue(list, new String[] {GlobalConst.CACHE_KEY_BASE_ORGAN},vo2);
          return list.get(0);
    }
    
    
    
   /**
    * 线路车辆
    * @param lineId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @Transactional
    public int getLineCar(String lineId) throws Exception {
        int lineCar =  (int) sqlMapDao.selectOne("lineAna.getLineCar", lineId);
		return lineCar;
    }
     
    /**
     * 在线车辆
     * @param lineId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @Transactional
     public int getOnlineCar(String lineId) throws Exception {
         int onlineCar =  (int) sqlMapDao.selectOne("lineAna.getOnlineCar", lineId);
         return onlineCar;
     }
     
   /**
    * 车辆列表
    * @param lineId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @Transactional
    public Pagination getRelatedCarPage(LineAnaLineVo lineVo) throws Exception {
        Pagination page = this.myBatisPage("lineAna.getRelatedCarCnt", "lineAna.getRelatedCarList", lineVo,LineRelevantCarVo.class);
        return page;
    }
    
    /**
     * 相关驾驶员
     * @param lineId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @Transactional
     public Pagination getRelatedDrvPage(String lineId) throws Exception {
         Pagination page = this.myBatisPage("lineAna.getRelatedDrvCnt", "lineAna.getRelatedDrvList", lineId,BaseDrvInfoEntity.class);
         Map<String,String> map = new HashMap<String,String>();
         map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);   
         FillParamsVo vo = new FillParamsVo("lineId", map);
         codeDscValue.fillInfoValue(page.getData(), new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO},vo);
         return page;
     }
    
   /**
    * 查询列表数据
    * @param vo
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<BiLineIdxInfoEntity> getLineIdxInfo(LineAnaLineVo vo) throws Exception {
         List<BiLineIdxInfoEntity>  list =  PubUtil.convertListMapToObject(
             this.sqlMapDao.selectList("lineAna.getLineIdxInfo", vo), BiLineIdxInfoEntity.class);
         return list;
    }
     
   /**
    * 查询排名
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getLineAnaRank(LineAnaLineVo vo) throws Exception {
        List<Map<String,Object>>  list =  this.sqlMapDao.selectList("lineAna.getLineAnaRank", vo) ;
        return list;
    }
      
   /**
    * 趋势图
    * @param vo
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getLineTrendInfo(LineAnaLineVo vo) throws Exception {
     List<Map<String,Object>> list = this.sqlMapDao.selectList("lineAna.getLineTrendInfo", vo);
        return list;
    }
      
   /**
    * 线路里程排名 
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings("unchecked")
    public List<Map<String,Object>> getLineEnerRankInfo(LineAnaLineVo vo) throws Exception {
    	List<Map<String,Object>> list = this.sqlMapDao.selectList("lineAna.getLineEnerRankInfo", vo) ;
        return list;
    }
    
    /**
     * 线路百公里能耗排名
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     public List<Map<String,Object>> getLineEnerHukRankInfo(LineAnaLineVo vo) throws Exception {
         List<Map<String,Object>> list = this.sqlMapDao.selectList("lineAna.getLineEnerHukRankInfo", vo) ;
         return list;
     }
     
    /**
     * 查询行为排名
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     public List<Map<String,Object>> getLineBehRankInfo(LineAnaLineVo vo) throws Exception {
     	List<Map<String,Object>> list = this.sqlMapDao.selectList("lineAna.getLineBehRankInfo", vo);
        return list;
     }
     
        
}
